package com.youlin.controller;

import com.youlin.dto.*;
import com.youlin.dto.req.EditFHReqDto;
import com.youlin.entities.BygAdmin;
import com.youlin.entities.BygFarewellHall;
import com.youlin.service.BygFarewellHallService;
import com.youlin.untils.AdminUtil;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 告别厅管理
 * @author ${author}
 * @since 2020-05-28
 */
@ApiSort(4)
@Api(tags = {"4 - 告别厅管理"})
@RestController
@RequestMapping("/bygFarewellHall")
public class BygFarewellHallController {

    @Autowired
    private BygFarewellHallService bygFarewellHallService;

    /**
     * 获取全部告别厅信息列表
     * @param baseReqDto
     * @return
     */
    @PostMapping("/findAllFHs")
    @ApiOperationSort(value = 1)
    @ApiOperation(value = "1 - 获取全部告别厅信息列表")
    public PageDataResDto<List<BygFarewellHall>> findAllFHs (@RequestBody PageReqDto baseReqDto) {
        PageInfo pageInfo = baseReqDto.getPageInfo();
        BygAdmin currentAdmin = AdminUtil.getCurrentAdmin();
        return bygFarewellHallService.findPageFHs (currentAdmin.getUnitId(), pageInfo);
    }

    /**
     * 新建或修改告别厅信息
     * @param baseReqDto
     * @return
     */
    @PostMapping("/editFH")
    @ApiOperationSort(value = 2)
    @ApiOperation(value = "2 - 新建或修改告别厅信息", notes = "响应参数：status-message = {1011-告别厅名称重复}")
    public BaseResDto editFH (@RequestBody BaseReqDto<EditFHReqDto> baseReqDto) {
        EditFHReqDto farewellHall = baseReqDto.getData();
        if (StringUtils.isBlank(farewellHall.getName()))
            return new BaseResDto(Status.PARAMETERERROR);
        BygAdmin currentAdmin = AdminUtil.getCurrentAdmin();
        return bygFarewellHallService.editFH (currentAdmin.getUnitId(), farewellHall);
    }

    /**
     * 逻辑删除告别厅信息
     * @param baseReqDto
     * @return
     */
    @PostMapping("/delFHById")
    @ApiOperationSort(value = 3)
    @ApiOperation(value = "3 - 逻辑删除告别厅信息", notes = "请求参数：data = 告别厅ID\n" +
            "响应参数：status-message = {1020-不能删除举行过告别会的告别厅}")
    public BaseResDto delFHById (@RequestBody BaseReqDto<Integer> baseReqDto) {
        Integer fhId = baseReqDto.getData();
        return bygFarewellHallService.delFHById (fhId);
    }

}

